package com.programmercarl.dp;

/**
 * https://leetcode.cn/problems/fibonacci-number/
 * 斐波那契数 AC
 *
 * @author yulongtian
 * @create 2025-02-09 10:38
 */
public class Test01 {
    public static void main(String[] args) {
        Test01 test01 = new Test01();
        System.out.println(test01.fib(30));
    }

    public int fib(int n) {
        if (n == 0 || n == 1) {
            return n;
        }
        int a = 0;
        int b = 1;
        int c = 0;
        for (int i = 2; i <= n; i++) {
            c = a + b;
            a = b;
            b = c;
        }
        return c;
    }
}
